﻿Imports TMySQL
Public Class frmColumn
    Private _Columns As TMyTableColumns
    Private Sub New()
        ' この呼び出しは、Windows フォーム デザイナで必要です。
        InitializeComponent()
        ' InitializeComponent() 呼び出しの後で初期化を追加します。
    End Sub
    Public Sub New(ByVal AColumns As TMyTableColumns)
        Me.New()
        _Columns = AColumns
        InitFrm()
    End Sub
    Private Sub InitFrm()
        cboColumn.Items.Clear()
        For i As Integer = 0 To _Columns.Count - 1
            cboColumn.Items.Add(_Columns(i).ColumnName & "[" & _Columns(i).ColumnType & "]")
        Next
        cboColumn.SelectedIndex = 0
    End Sub
    Public ReadOnly Property ColumnName() As String
        Get
            Return cboColumn.SelectedItem
        End Get
    End Property
    Public ReadOnly Property IndexSize() As Integer
        Get
            Return Common.StrToIntDef(txtSize.Text, 0)
        End Get
    End Property
    Public ReadOnly Property ColumnSQL() As String
        Get
            Dim column As TMyTableColumn = _Columns(cboColumn.SelectedIndex)
            Dim sb As New System.Text.StringBuilder
            sb.Append("`").Append(column.ColumnName).Append("`")
            If column.ColumnType.Contains("CHAR") AndAlso Me.IndexSize > 0 Then
                sb.Append("(").Append(txtSize.Text).Append(")")
            End If
            Return sb.ToString
        End Get
    End Property
    Private Sub txtSize_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtSize.KeyPress
        If e.KeyChar < "0"c OrElse e.KeyChar > "9"c Then
            e.Handled = True
        End If
    End Sub
End Class